package sample;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Controller {

    @FXML
    private TextField inputDate;
    @FXML
    private TextArea resultText;

    @FXML
    public void initialize() {
        inputDate.setText(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日")));
    }

    @FXML
    public void onTransferBtnClick(ActionEvent actionEvent) {
        String inputDateText = inputDate.getText();
        LocalDate localDate = LocalDate.parse(inputDateText, DateTimeFormatter.ofPattern("[yyyy-MM-dd][yyyy-M-d][yyyy年M月d日][yyyy年MM月dd日]"));
        // 1天后
        LocalDate oneDayAfter = localDate.plusDays(1);
        // 1周后
        LocalDate oneWeekAfter = localDate.plusWeeks(1);
        // 2周后
        LocalDate twoWeekAfter = localDate.plusWeeks(2);
        // 1月后
        LocalDate oneMonthAfter = localDate.plusMonths(1);

        // 格式化输出结果
        DateTimeFormatter outputDateFormat = DateTimeFormatter.ofPattern("yyyy年MM月dd日");
        StringBuilder resultBuilder = new StringBuilder();
        resultBuilder.append(oneDayAfter.format(outputDateFormat));
        resultBuilder.append("\n");
        resultBuilder.append(oneWeekAfter.format(outputDateFormat));
        resultBuilder.append("\n");
        resultBuilder.append(twoWeekAfter.format(outputDateFormat));
        resultBuilder.append("\n");
        resultBuilder.append(oneMonthAfter.format(outputDateFormat));

        resultText.setText(resultBuilder.toString());
    }

    public void onCopyClipboard(ActionEvent actionEvent) {
        final Clipboard clipboard = Clipboard.getSystemClipboard();
        final ClipboardContent content = new ClipboardContent();
        content.putString(resultText.getText());
        clipboard.setContent(content);
    }
}
